package com.esms.struts.service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.esms.bean.Notice;
import com.esms.bean.NoticeDAO;
import com.esms.bean.Person;

public class NoticeService {
	private NoticeService() {}
	public static NoticeService $ = new NoticeService(); 
	
	public List retrieveBirthdayReminders(String userid) {
		List resultList = null;
		Person currentUser = PersonService.$.getPerson(userid);
		int m,d;
		Calendar cal = Calendar.getInstance();
		m = cal.get(Calendar.MONTH) + 1;
		d = cal.get(Calendar.DATE); 
		String today = m + "-" + d;
		List reminders = NoticeDAO.$.findByName("person_create");
		if(null == reminders)
			return null;
		for(int i = 0, n = reminders.size(); i < n; i++) {
			Notice notice = (Notice) reminders.get(i);
			String description = notice.getDescription();
			if(description.contains(today)) {
				if(description.contains(userid)) {
					resultList = new ArrayList(1);
					resultList.add(notice);
					break;
				}
			}
		}
		return resultList;
	}
	
	public List getAllNotices() {
		List notices = NoticeDAO.$.findAll();
		return notices;
	}
	
	public static void main(String[] args) {
		int m,d;
		Calendar cal = Calendar.getInstance();
		m = cal.get(Calendar.MONTH) + 1;
		d = cal.get(Calendar.DATE); 
		String today = m + "-" + d;
		System.out.println(today);
	} 
}
